package com.ruoyi.redtea.dualprevent.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.redtea.dualprevent.domain.bo.TrainUserInfoBo;
import com.ruoyi.redtea.dualprevent.domain.entity.TrainUser;
import com.ruoyi.redtea.dualprevent.domain.vo.TrainUserInfoVo;
import com.ruoyi.redtea.dualprevent.service.TrainUserInfoService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息管理
 *
 * @author makejava
 * @since 2024-05-14 09:39:38
 */
@RestController
@RequestMapping("trainUserInfo")
public class TrainUserInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TrainUserInfoService trainUserInfoService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param trainUser 查询实体
     * @return 所有数据
     */
    @GetMapping("listAll")
    public AjaxResult selectAll(Page<TrainUser> page, TrainUser trainUser) {
//        return success(this.trainUserInfoService.page(page, new QueryWrapper<>(trainUser)));
        List<TrainUserInfoVo> trainUserInfoVos = trainUserInfoService.selectList();
        return success(trainUserInfoVos);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Long id) {
//        return success(this.trainUserInfoService.getById(id));
        TrainUserInfoVo trainUserInfoVo = trainUserInfoService.queryUserInfoById(id);
        if(trainUserInfoVo!=null){
            return success(trainUserInfoVo);
        }else {
            return error("没查到");
        }
    }

    /**
     * 新增数据
     *
     * @param trainUserInfoBo 实体对象
     * @return 新增结果
     */
    @PostMapping("createUserInfo")
    public AjaxResult insert(@RequestBody TrainUserInfoBo trainUserInfoBo) {
        boolean insertUserInfo = trainUserInfoService.insertUserInfo(trainUserInfoBo);
        if(insertUserInfo){
            return success("更新成功");
        }else {
            return error("更新失败");
        }
    }

/*    *//**
     * 修改数据
     *
     * @param trainUser 实体对象
     * @return 修改结果
     *//*
    @PutMapping
    public AjaxResult update(@RequestBody TrainUser trainUser) {
        return success(this.trainUserInfoService.updateById(trainUser));
    }

    *//**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     *//*
    @DeleteMapping
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return success(this.trainUserInfoService.removeByIds(idList));
    }*/
}

